using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(ActionDistance))]
public class Note : MonoBehaviour
{
    //[SerializeField] private PageInformation inf;
    [SerializeField] private GameObject notePrefab;
    /*[SerializeField]*/
    private Transform parent;
    [SerializeField] private string ID;

    private GameObject note;
    private ObjectState n;
    private ActionDistance action;

    void Start()
    {
        n = PlayerData.FindObject(ID);

        if (n.id == null)
        {
            n = PlayerData.AddObjectState(ID, true);
        }
        else
        {
            gameObject.SetActive(n.isActive);
        }

        action = gameObject.GetComponent<ActionDistance>();
        action.s = false;

        parent = GameObject.FindGameObjectWithTag("Parent").transform;
    }

    private void OnMouseDown()
    {
        if (action.s && PlayerData.ParentObject.transform.childCount==0)
        {
            note = Instantiate(notePrefab, parent);
            Transform g = note.transform.GetChild(0).GetComponent<Transform>(); 

            gameObject.GetComponent<INote>().ShowNote(g);

            n.isActive = false;
            gameObject.SetActive(false);
        }
    }

   


}
